﻿Imports System.Data
Imports System.Data.OleDb
Imports System.Windows.Forms
Public Class Connection
    Dim connect As OleDbConnection
    Dim command As OleDbCommand
    Dim stringConnect As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='QuanLyTiecCuoi.mdb'"

    Public Sub connecting()
        Try
            connect = New OleDbConnection(stringConnect)
            connect.Open()
        Catch ex As Exception
            MessageBox.Show("Kết nối thất bại !" + vbNewLine + ex.Message, "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Public Sub Close()
        If connect.State = ConnectionState.Open Then
            connect.Close()
        End If
    End Sub

    Public Function LoadData(ByVal stringCommand As String) As DataTable
        Dim dt As New DataTable
        connecting()
        command = New OleDbCommand(stringCommand, connect)
        Dim dataadapter As New OleDbDataAdapter(command)
        dataadapter.Fill(dt)
        Close()
        Return dt
    End Function

    Public Function ExecuteData(ByVal stringCommand As String)
        command = New OleDbCommand(stringCommand, connect)
        Return command.ExecuteNonQuery()
    End Function
End Class
